package com.example.demo.controller;

import com.example.demo.config.AjaxResult;
import com.example.demo.model.UserInfo;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录入口
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 注册
     * @param userInfo
     */
    @RequestMapping("/reg")
    public AjaxResult reg(UserInfo userInfo) {
        //非空校验
        if(userInfo == null || !StringUtils.hasLength(userInfo.getUsername()) ||
        !StringUtils.hasLength(userInfo.getPassword())) {
            return AjaxResult.error(403, "非法注册，请重试！");
        }
        return AjaxResult.success(userService.RegService(userInfo));
    }

    @RequestMapping("/login")
    public String login() {
        return "hi";
    }

}
